<html>
<head>
  <title>examples.php</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<pre>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
	   &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot; xml:lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;HttpClient Examples&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;http://www.incutio.com/css/basic.css&quot; type=&quot;text/css&quot; /&gt;
&lt;style type=&quot;text/css&quot; media=&quot;screen&quot;&gt;
@import &quot;http://www.incutio.com/css/layout.css&quot;;
.leftmenu ul {
    margin: 0px;
    padding: 0px 0px 10px 15px;
    list-style-type: square;
}
h3 {
    margin-bottom: 1em;
}
dl {
    width: 80%;
    margin-left: 10px;
}
dt {
    font-weight: bold;
    line-height: 1.4em;
}
pre {
    margin: 15px;
    padding: 10px;
    border: 1px dashed #ccc;
    color: #006;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;Header&quot;&gt;&lt;img id=&quot;IncutioLogo&quot; src=&quot;/images/incutiologo.gif&quot; alt=&quot;Logo: Incutio Limited, Be Inspired&quot; /&gt;&lt;img id=&quot;ScriptsLogo&quot; src=&quot;/images/scriptslogo.gif&quot; alt=&quot;scripts.incutio.com&quot; /&gt;&lt;div style=&quot;clear:both&quot;&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div id=&quot;TopNavBar&quot;&gt;
&lt;a href=&quot;http://www.incutio.com/&quot;&gt;INCUTIO HOME&lt;/a&gt;&lt;span&gt; | &lt;/span&gt;
&lt;a href=&quot;http://scripts.incutio.com/&quot;&gt;SCRIPTS&lt;/a&gt;&lt;span&gt; | &lt;/span&gt;
&lt;a href=&quot;http://www.incutio.com/contact/&quot;&gt;CONTACT&lt;/a&gt;
&lt;/div&gt;
&lt;div id=&quot;MainContentCell&quot;&gt;
	&lt;div id=&quot;MainBodyContent&quot;&gt;

&lt;h2&gt;HttpClient Examples&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;index.php&quot;&gt;HttpClient Home&lt;/a&gt; | &lt;a href=&quot;HttpClient.class.php&quot; title=&quot;HttpClient.class.php&quot;&gt;Download HttpClient (txt)&lt;/a&gt; | &lt;a href=&quot;manual.php&quot;&gt;HttpClient Manual&lt;/a&gt; | &lt;a href=&quot;demo.php&quot;&gt;HttpClient Demo&lt;/a&gt;&lt;/p&gt;&lt;/p&gt;

&lt;h3&gt;Grabbing an HTML page (static method)&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$pageContents = HttpClient::quickGet('http://example.com/');&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Posting a form and grabbing the response (static method)&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$pageContents = HttpClient::quickPost('http://example.com/someForm', array(
    'name' =&gt; 'Some Name',
    'email' =&gt; 'email@example.com'
));&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The static methods are easy to use, but seriously limit the functionality of the class as you cannot access returned headers or use facilities such as cookies or authentication.&lt;/p&gt;

&lt;h3&gt;A simple GET request using the class&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
if (!$client-&gt;get('/')) {
    die('An error occurred: '.$client-&gt;getError());
}
$pageContents = $client-&gt;getContent();&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;A GET request with debugging turned on&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
$client-&gt;setDebug(true);
if (!$client-&gt;get('/')) {
    die('An error occurred: '.$client-&gt;getError());
}
$pageContents = $client-&gt;getContent();&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;A GET request demonstrating automatic redirection&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('www.amazon.com');
$client-&gt;setDebug(true);
if (!$client-&gt;get('/')) {
    die('An error occurred: '.$client-&gt;getError());
}
$pageContents = $client-&gt;getContent();&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Check to see if a page exists&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
$client-&gt;setDebug(true);
if (!$client-&gt;get('/thispagedoesnotexist')) {
    die('An error occurred: '.$client-&gt;getError());
}
if ($client-&gt;getStatus() == '404') {
    echo 'Page does not exist!';
}
$pageContents = $client-&gt;getContent();&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Fake the User Agent string&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
$client-&gt;setDebug(true);
$client-&gt;setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021207');
if (!$client-&gt;get('/')) {
    die('An error occurred: '.$client-&gt;getError());
}
$pageContents = $client-&gt;getContent();&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Log in to a site via a login form, then request a page&lt;/h3&gt;

&lt;p&gt;In this example, it is assumed that correctly logging in will result in the server sending a sesssion cookie of some sort. This cookie is resent by the HttpClient class automatically, so a request to a page that requires users to be logged in will now work.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
$client-&gt;post('/login.php', array(
    'username' =&gt; 'Simon',
    'password' =&gt; 'ducks'
));
if (!$client-&gt;get('/private.php')) {
    die('An error occurred: '.$client-&gt;getError());
}
$pageContents = $client-&gt;getContent();
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Using HTTP authorisation&lt;/h3&gt;

&lt;p&gt;Note that the class uses the American spelling 'authorization' to fit with the &lt;acronym title=&quot;HyperText Transfer Protocol&quot;&gt;HTTP&lt;/acronym&gt; specification.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
$client-&gt;setAuthorization('Username', 'Password');
if (!$client-&gt;get('/')) {
    die('An error occurred: '.$client-&gt;getError());
}
$pageContents = $client-&gt;getContent();
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Print out the headers from a response&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('example.com');
if (!$client-&gt;get('/')) {
    die('An error occurred: '.$client-&gt;getError());
}
print_r($client-&gt;getHeaders());
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Setting the maximum number of redirects&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$client = new HttpClient('www.amazon.com');
$client-&gt;setDebug(true);
$client-&gt;setMaxRedirects(3);
$client-&gt;get('/');
&lt;/code&gt;&lt;/pre&gt;

	&lt;div id=&quot;LeftMenu&quot;&gt;
		&lt;div class=&quot;fieldsetPartners&quot;&gt;
				&lt;span class=&quot;legendPartners&quot;&gt;Scripts&lt;/span&gt;
&lt;div class=&quot;leftmenu&quot;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;/&quot;&gt;Scripts Home&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;/xmlrpc/&quot;&gt;PHP XML-RPC Library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/amazon/&quot;&gt;PHP Amazon Search&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/google/&quot;&gt;PHP Google Web API&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;/incDirectory/&quot;&gt;incDirectory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;/sslinks/&quot;&gt;ssLinks&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;!-- BEGIN LivePerson Button Code --&gt;&lt;table border='0' cellspacing='0' cellpadding='0'&gt;&lt;tr&gt;&lt;td align='center'&gt;&lt;a href='http://server.iad.liveperson.net/hc/52472728/?cmd=file&amp;file=visitorWantsToChat&amp;site=52472728&amp;byhref=1' target='chat52472728' onClick=&quot;javascript:window.open('http://server.iad.liveperson.net/hc/52472728/?cmd=file&amp;file=visitorWantsToChat&amp;site=52472728&amp;referrer='+document.location,'chat52472728','width=472,height=320');return false;&quot;&gt;&lt;img src='http://server.iad.liveperson.net/hc/52472728/?cmd=repstate&amp;site=52472728&amp;category=en;woman;2&amp;ver=1' name='hcIcon' width=110 border=0&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;!-- END LivePerson Button code --&gt;

&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	
		&lt;div id=&quot;RightGutter&quot;&gt;
			&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img src=&quot;../images/light.gif&quot; alt=&quot;scripts.incutio.com light logo&quot; style=&quot;width: 81px; margin-top: 10px&quot;/&gt;&lt;/div&gt;
		&lt;/div&gt;
	&lt;/div&gt;
	
&lt;/div&gt;
&lt;div id=&quot;Footer&quot;&gt;
	Design, Content, Images &amp;copy; 2002 Incutio Limited | &lt;a href=&quot;http://validator.w3.org/check/referer&quot;&gt;W3C XHTML 1.0&lt;/a&gt;
&lt;/div&gt;
&lt;!-- BEGIN HumanTag Monitor. DO NOT MOVE! MUST BE PLACED JUST BEFORE THE /BODY TAG --&gt;&lt;script language='javascript' src='http://server.iad.liveperson.net/hc/52472728/x.js?cmd=file&amp;file=chatScript3&amp;site=52472728&amp;category=en;woman;2'&gt; &lt;/script&gt;&lt;!-- END HumanTag Monitor. DO NOT MOVE! MUST BE PLACED JUST BEFORE THE /BODY TAG --&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<hr>
syntax highlighted by <a href="http://www.palfrader.org/code2html">Code2HTML</a>, v. 0.9.1
</body>
</html>
